import { Controller, Get } from "@nestjs/common";
import { isStr, isEmpty } from "st-common-core";
import { genRes, ResObjPropNameConst } from "st-common-req";
import { RsaService } from "./rsa.service";

/**
 * RSA 控制器
 */
@Controller("rsa")
export class RsaController {

  constructor(
    private readonly rsaService: RsaService
  ) {
  }

  @Get("common/pub")
  getRsaCommonPubKey() {
    // 获取 RSA 通用公钥
    const rsaCommonPubKey = this.rsaService.getRsaCommonPubKey();
    // 如果获取 RSA 通用公钥失败
    if (!isStr(rsaCommonPubKey) || isEmpty(rsaCommonPubKey)) return genRes({
      [ResObjPropNameConst.STATUS]: false,
      [ResObjPropNameConst.MESSAGE]: "获取 RSA 通用公钥失败"
    })
    // 获取 RSA 通用公钥成功
    return genRes({
      [ResObjPropNameConst.MESSAGE]: "获取 RSA 通用公钥成功",
      [ResObjPropNameConst.DATA]: rsaCommonPubKey
    })
  }

}
